require "Common/define"
require "Logic/Config"
require "Common/functions"

RedDotsCrossTeamArenaBattleHandler ={};
local this = RedDotsCrossTeamArenaBattleHandler

function RedDotsCrossTeamArenaBattleHandler.init()
    CloseEvent(Config.EventType.Fresh_Cross_Team_Arena,this.update)
    ListenEvent(Config.EventType.Fresh_Cross_Team_Arena,this.update)
    -- CloseEvent(Config.EventType.refreshDefFormation, this.update)
    -- ListenEvent(Config.EventType.refreshDefFormation, this.update)
    CloseEvent(Config.EventType.Fresh_CrossTeamRewardPreview, this.update)
    ListenEvent(Config.EventType.Fresh_CrossTeamRewardPreview, this.update)
    CloseEvent(Config.EventType.Fresh_NewStage, this.update)
    ListenEvent(Config.EventType.Fresh_NewStage, this.update)
    CloseEvent(Config.EventType.Fresh_CrossTeamArenaRed, this.update)
    ListenEvent(Config.EventType.Fresh_CrossTeamArenaRed, this.update)
    return this
end


--参数 无
function RedDotsCrossTeamArenaBattleHandler.getFlag(...)
 
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.CrossTeamArena, false) then
        -- local crossTeamArenaBaseoInfo = logicMgr.ArenaManager.getCrossTeamBaseInfo()
        -- if crossTeamArenaBaseoInfo.freeTimes > crossTeamArenaBaseoInfo.times and (crossTeamArenaBaseoInfo.endTime - Config.serverTime) > 0 then
        --     return Config.RedDotsFlagState.Needful
        -- end
        -- if logicMgr.FormationManager.checkDefFormationRedDotByType(EnumConst.FormationType.TeamCrossArenaDef) then
        --     return Config.RedDotsFlagState.Needful
        -- end
        if Util.GetPlayerPrefs("RedDotsCrossTeamArenaBattle"..logicMgr.HeroManager.GetRoleInfo().playerId) == nil then
            return Config.RedDotsFlagState.Needful
        end
        if logicMgr.ArenaManager.getCrossTeamOpenStatus() then
            return Config.RedDotsFlagState.Needful
        end
         local crossTeamArenaBaseoInfo = logicMgr.ArenaManager.getCrossTeamBaseInfo()
        local _, cfg_arena_matching_item = ArenaManager.getAthleticGradingConfigByRank(crossTeamArenaBaseoInfo.rank)
        if cfg_arena_matching_item ~= nil and crossTeamArenaBaseoInfo.award >= cfg_arena_matching_item.f_CoinLimit then
            return Config.RedDotsFlagState.Needful
        end
        local data = logicMgr.ArenaManager.GetCrossTeamNewDuanWeiAward()
        if data ~= nil then
            for _, v in pairs(data) do
                if v and tostring(v) == "1" then
                    return Config.RedDotsFlagState.Needful
                end
            end
        end
    end
    return Config.RedDotsFlagState.None
end


function RedDotsCrossTeamArenaBattleHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.CrossTeamArenaBattle)
end